otutil: Add some more GIO helpers
authorColin Walters <walters@verbum.org>
Tue, 8 Nov 2011 23:13:48 +0000 (18:13 -0500)
committerColin Walters <walters@verbum.org>
Wed, 9 Nov 2011 00:00:28 +0000 (19:00 -0500)
libotutil/ot-gio-utils.c
libotutil/ot-gio-utils.h

index ad172de73eced4057033a72377a555c60223140d..b13b24ed4c0e0724d2572bff96fa7fcc32844c66 100644 (file)
@@ -146,3 +146,32 @@ ot_util_new_file_for_path (const char *path)
 {
   return g_vfs_get_file_for_path (g_vfs_get_local (), path);
 }
+
+const char *
+ot_gfile_get_path_cached (GFile *file)
+{
+  const char *path;
+
+  path = g_object_get_data ((GObject*)file, "ostree-file-path");
+  if (!path)
+    {
+      path = g_file_get_path (file);
+      g_object_set_data_full ((GObject*)file, "ostree-file-path", (char*)path, (GDestroyNotify)g_free);
+    }
+  return path;
+}
+
+
+const char *
+ot_gfile_get_basename_cached (GFile *file)
+{
+  const char *name;
+
+  name = g_object_get_data ((GObject*)file, "ostree-file-name");
+  if (!name)
+    {
+      name = g_file_get_basename (file);
+      g_object_set_data_full ((GObject*)file, "ostree-file-name", (char*)name, (GDestroyNotify)g_free);
+    }
+  return name;
+}
index 0acb4dc911757b1d0e4280a1f9621fbdeddec291..15c5960d3670a265132f5b8ff746e551def37a2c 100644 (file)
@@ -28,6 +28,10 @@ G_BEGIN_DECLS
 
 GFile *ot_util_new_file_for_path (const char *path);
 
+const char *ot_gfile_get_path_cached (GFile *file);
+
+const char *ot_gfile_get_basename_cached (GFile *file);
+
 gboolean ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error);
 
 char * ot_util_get_file_contents_utf8 (const char *path, GError    **error);